<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="频道号">
              <a-input placeholder="请输入频道号" v-model="queryParam.channelNumber"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="频道名称">
              <a-input placeholder="请输入频道名称" v-model="queryParam.channelName"></a-input>
            </a-form-item>
          </a-col>

         <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="节目单记录的内容ID">
              <a-input placeholder="请输入节目单记录的内容ID" v-model="queryParam.scheduleId"></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="虚拟排单元素类型">
              <j-dict-select-tag placeholder="请选择虚拟排单元素类型" v-model="queryParam.scheduleType" dictCode="gd_schedule_type"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="节目名称">
                <a-input placeholder="请输入节目名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <!--  <a-form-item label="播放开始日期yyyyMMdd">
                <a-input placeholder="请输入播放开始日期，格式：yyyyMMdd" v-model="queryParam.startDate"></a-input>
              </a-form-item>-->

              <a-form-item label="播放日期">
                <j-date placeholder="请选择开始日期" class="query-group-cust" date-format="YYYYMMDD" v-model="queryParam.startDate_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" date-format="YYYYMMDD" v-model="queryParam.startDate_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="开始时间HHmmss">
                <a-input placeholder="请输入开始时：HHmmss" v-model="queryParam.startTime"></a-input>
              </a-form-item>
            </a-col>
            <!--<a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="播放开始时间戳，到 1970-1-1 的秒数">
                <a-input placeholder="请输入播放开始时间戳，到 1970-1-1 的秒数" v-model="queryParam.startTimestamp"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="播放结束时间戳，到 1970-1-1 的秒数">
                <a-input placeholder="请输入播放结束时间戳，到 1970-1-1 的秒数" v-model="queryParam.endTimestamp"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="播放时长,格式HHmmss">
                <a-input placeholder="请输入播放时长,格式HHmmss" v-model="queryParam.duration"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="水印图标">
                <a-input placeholder="请输入水印图标" v-model="queryParam.watermarkUrl"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="水印图标的位置">
                <a-input placeholder="请输入水印图标的位置" v-model="queryParam.watermarkPos"></a-input>
              </a-form-item>
            </a-col>-->
           <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否显示节目">
                <j-dict-select-tag placeholder="请选择是否显示节目" v-model="queryParam.dispFlag" dictCode="gd_disp_flag"/>
              </a-form-item>
            </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否支持回看">
                <j-dict-select-tag placeholder="是否支持回看" v-model="queryParam.status" dictCode="gd_status"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="类型">
                <j-dict-select-tag placeholder="请选择类型" v-model="queryParam.type" dictCode="gd_type"/>
              </a-form-item>
            </a-col>
           <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="回看类型">
                <j-dict-select-tag placeholder="请选择回看类型" v-model="queryParam.reviewType" dictCode="review_type"/>
              </a-form-item>
            </a-col>-->
            <!--<a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="频道id">
                <a-input placeholder="请输入频道id" v-model="queryParam.channelId"></a-input>
              </a-form-item>
            </a-col>
-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否打标签">
                <j-dict-select-tag placeholder="请选择是否打标签" v-model="queryParam.isLabel" dictCode="gd_lable"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('广电节目单')">导出</a-button>-->
    <!--  <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <!-- 高级查询区域 -->
     <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
     --> <a-dropdown v-if="selectedRowKeys.length > 0">

      <a-menu slot="overlay" @click="handleMenuClick">
        <a-menu-item key="1">
          <a-icon  @click="batchLable('1')"/>
          综艺
        </a-menu-item>
        <a-menu-item key="2">
          <a-icon  @click="batchLable('2')"/>
          体育
        </a-menu-item>
        <a-menu-item key="3">
          <a-icon  @click="batchLable('3')"/>
          电影
        </a-menu-item>

        <a-menu-item key="4">
          <a-icon  @click="batchLable('4')"/>
          电视剧
        </a-menu-item>

        <a-menu-item key="5">
          <a-icon  @click="batchLable('5')"/>
          热门
        </a-menu-item>
      </a-menu>

        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <gd-programme-modal ref="modalForm" @ok="modalFormOk"></gd-programme-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import GdProgrammeModal from './modules/GdProgrammeModal'
  import {lableBatch} from '@/api/api'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'GdProgrammeList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      GdProgrammeModal
    },
    data () {
      return {
        description: '广电节目单管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },

          {
            title:'频道号',
            align:"center",
            dataIndex: 'channelNumber'
          },
          {
            title:'频道名称',
            align:"center",
            dataIndex: 'channelName'
          },
          /*{
            title:'节目单记录的内容ID',
            align:"center",
            dataIndex: 'scheduleId'
          },*/
          {
            title:'虚拟排单元素类型',
            align:"center",
            dataIndex: 'scheduleType_dictText'
          },
          {
            title:'节目名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'开始日期：yyyyMMdd',
            align:"center",
            dataIndex: 'startDate'
          },
          {
            title:'开始时间：HHmmss',
            align:"center",
            dataIndex: 'startTime'
          },
          /*{
            title:'播放开始时间戳，到 1970-1-1 的秒数',
            align:"center",
            dataIndex: 'startTimestamp'
          },
          {
            title:'播放结束时间戳，到 1970-1-1 的秒数',
            align:"center",
            dataIndex: 'endTimestamp'
          },
          {
            title:'播放时长,格式HHmmss',
            align:"center",
            dataIndex: 'duration'
          },
          {
            title:'水印图标',
            align:"center",
            dataIndex: 'watermarkUrl'
          },
          {
            title:'水印图标的位置',
            align:"center",
            dataIndex: 'watermarkPos'
          },*/
         /* {
            title:'是否显示节目',
            align:"center",
            dataIndex: 'dispFlag_dictText'
          },*/
          {
            title:'是否支持回看',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'type_dictText'
          },
          {
            title:'是否打标签',
            align:"center",
            dataIndex: 'isLabel_dictText'
          },
        /*  {
            title:'回看类型',
            align:"center",
            dataIndex: 'reviewType_dictText'
          },*/
         /* {
            title:'请求时间',
            align:"center",
            dataIndex: 'reqTime'
          },
          {
            title:'频道id',
            align:"center",
            dataIndex: 'channelId'
          },*/

          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/gd/gdProgramme/list",
          delete: "/gd/gdProgramme/delete",
          deleteBatch: "/gd/gdProgramme/deleteBatch",
          exportXlsUrl: "/gd/gdProgramme/exportXls",
          importExcelUrl: "gd/gdProgramme/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },

      batchLable: function (status) {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return false;
        } else {
          let ids = "";
          let that = this;
          let isAdmin = false;
        /*  that.selectionRows.forEach(function (row) {
            if (row.username == 'admin') {
              isAdmin = true;
            }
          });*/

          that.selectedRowKeys.forEach(function (val) {
            ids += val + ",";
          });
          let remark = "";
          if(status == 1){
            remark = "综艺";
          }
          if(status == 2){
            remark = "体育";
          }
          if(status == 3){
            remark = "电影";
          }
          if(status == 4){
            remark = "电视剧";
          }
          if(status == 5){
            remark = "热门";
          }
          that.$confirm({
            title: "确认操作",
            //content: "选中数据是否批量变更为?",
            content: "选中数据是否批量变更为" + remark+ "?",
            onOk: function () {
              lableBatch({ids: ids, status: status}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              });
            }
          });
        }
      },

      handleMenuClick(e) {
        if (e.key == 1) {
          this.batchLable(1);
        } else if (e.key == 2) {
          this.batchLable(2);
        } else if (e.key == 3) {
          this.batchLable(3);
        } else if (e.key == 4) {
          this.batchLable(4);
        } else if (e.key == 5) {
          this.batchLable(5);
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'scheduleId',text:'节目单记录的内容ID',dictCode:''})
        fieldList.push({type:'int',value:'scheduleType',text:'虚拟排单元素类型：',dictCode:'gd_schedule_type'})
        fieldList.push({type:'string',value:'name',text:'节目名称',dictCode:''})
        fieldList.push({type:'string',value:'startDate',text:'客户端播放开始日期，格式：yyyyMMdd',dictCode:''})
        fieldList.push({type:'string',value:'startTime',text:'客户端播放开始时间，格式：HHmmss',dictCode:''})
        fieldList.push({type:'int',value:'startTimestamp',text:'播放开始时间戳，到 1970-1-1 的秒数',dictCode:''})
        fieldList.push({type:'int',value:'endTimestamp',text:'播放结束时间戳，到 1970-1-1 的秒数',dictCode:''})
        fieldList.push({type:'string',value:'duration',text:'播放时长,格式HHmmss',dictCode:''})
        fieldList.push({type:'string',value:'watermarkUrl',text:'水印图标',dictCode:''})
        fieldList.push({type:'int',value:'watermarkPos',text:'水印图标的位置',dictCode:''})
        fieldList.push({type:'int',value:'dispFlag',text:'是否显示该条节目名称',dictCode:'gd_disp_flag'})
        fieldList.push({type:'int',value:'status',text:'状态标志，标识节目单是否可用',dictCode:'gd_status'})
        fieldList.push({type:'int',value:'type',text:'类型',dictCode:'gd_type'})
        fieldList.push({type:'string',value:'reviewType',text:'回看类型',dictCode:'review_type'})
        fieldList.push({type:'string',value:'reqTime',text:'请求时间',dictCode:''})
        fieldList.push({type:'string',value:'channelId',text:'频道id',dictCode:''})
        fieldList.push({type:'string',value:'channelNumber',text:'频道号',dictCode:''})
        fieldList.push({type:'string',value:'channelName',text:'频道名称',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>